package za.ac.cput.arrowgame.service.requesthandler;

import org.springframework.stereotype.Component;
import za.ac.cput.arrowgame.app.exceptions.InvalidInput;
import za.ac.cput.arrowgame.app.exceptions.Win;
import za.ac.cput.arrowgame.app.facade.Facade;
import za.ac.cput.arrowgame.model.Grid;

@Component("handleMove")
public class HandleMove extends Handler {

    @Override
    public Grid handleRequest(Command command, Grid gridModel) throws InvalidInput, Win, InterruptedException {
        if ("F".equalsIgnoreCase(command.getMove())) {
            final Integer amount = command.getAmount();
            for (int i = 0; i < amount; i++) {
                gridModel = Facade.getInstance().getMoveArrowService().moveArrowForward(gridModel);
            }
        } else if (successorHandler != null) {
            successorHandler.handleRequest(command, gridModel);
        }
        return gridModel;
    }
}
